<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/layouts/include/taglib.jsp" %> 

<!DOCTYPE html>
<html lang="zh-cn">
<head>
<title>员工管理</title>
<meta charset="utf-8">
<meta name="decorator" content="default" />
</head>
<body>

<script type="text/javascript">
$(function(){
	//$(".select2").select2(); 
	//初始化tooltip
	$('[data-rel=tooltip]').tooltip();
});
</script>

<script type="text/javascript">
//初始化datatable
var datatable;
$(function() {
	datatable = $('#empTable').dataTable({
						"oLanguage" : oLanguage,
						"bFilter" : false,
						"bSort" : false,
						"bProcessing" : true,
						"bServerSide" : true,
						"bLengthChange" : false,
						"bInfo" : true,
						"bPaginate" : true,
						"sAjaxSource" : "${ctx}/sys/emp/list.do",
						"fnServerData": function(sSource, aoData, fnCallback,oSettings){
		            		$.extend(aoData,$('#queryForm').serializeArray());
		            		$.ajax({
		        	    		dataType: 'json',
		        	    		url : sSource,
		        	    		data: aoData,
		        	    		success: fnCallback
		            		});		
		              	},
						"aoColumns" : [
						        {
						        	"mData" : null,
						        	"sClass" : "center",
						        	"mRender" : function(data, type, full) {
										return '<a href="#" title="修改" onclick="update(\''+full.uuid+'\');return false;"  data-action="settings"><i class="icon-pencil"></i></a>&nbsp;&nbsp;<a class="red" title="删除" href="javascript:del(\''+full.uuid+'\',\''+full.empName+'\')"><i class="icon-trash bigger-130"></i></a>&nbsp;&nbsp;<a class="green" title="重置密码" href="javascript:resetPassword(\''+full.uuid+'\')"><i class="icon-undo bigger-130"></i></a>';
									}
						        },
								 {
									"mData" : "empNo"
								}, {
									"mData" : "empName"
								} , {
									"mData" : "roleNames"
								}]

					});
});



//查询
function query() {
	var oSettings = datatable.fnSettings();
	oSettings._iDisplayStart = 0;
	datatable.fnClearTable(0); //清空数据
	datatable.fnDraw(); //重新加载数据 
}
//增加
function add() {
	window.location = "${ctx}/jsp/sys/emp/emp.jsp?type=add"; 
}

//删除
function del(uuid,empName) {
	// 删除的时候添加提示
	Otod.Msg.confirm('确定删除此员工【'+empName+'】?',"确认删除", function(){
		Otod.ajax({
			type : "get",
			url : '${ctx}/sys/emp/deleteById.do',
			data : {
				"uuid" : uuid
			},
			successFn : function(data) {
				Otod.Msg.info(data.info);
				datatable.fnDraw(); //重新加载数据 
			}
		})
      		
    });
}
//修改
function update(uuid) {
	if (uuid ==null||uuid=='') {
		BootstrapDialog.show({
			type : BootstrapDialog.TYPE_INFO,
			title : '提示',
			message : '你还没有选择任何记录！',
			buttons : [ {
				label : '确定',
				cssClass : 'btn-info',
				action : function(dialogRef) {
					dialogRef.close();
				}
			} ]
		});
		return;
	}
	/* if ($("input[name=selectEmp]:checked").size() > 1) {
		BootstrapDialog.show({
			type : BootstrapDialog.TYPE_WARNING,
			title : '提示',
			message : '一次只能修改一条数据！',
			buttons : [ {
				label : '确定',
				cssClass : 'btn-warning',
				action : function(dialogRef) {
					dialogRef.close();
				}
			} ]
		});
		return;
	} */
	var empId = uuid;
	window.location = "${ctx}/jsp/sys/emp/emp.jsp?type=update&empId="+ empId;
}

//重置密码
function resetPassword(uuid) {
	if (uuid != null || uuid != '') {
		Otod.ajax({
			type : "get",
			url : '${ctx}/sys/emp/resetPassword.do',
			data : {
				"uuid" : uuid
			},
			successFn : function(data) {
				Otod.Msg.info(data.info);
				
			}
		});
	} else {
		BootstrapDialog.show({
			type : BootstrapDialog.TYPE_INFO,
			title : '提示',
			message : '重置失败',
			buttons : [ {
				label : '确定',
				cssClass : 'btn-info',
				action : function(dialogRef) {
					dialogRef.close();
				}
			} ]
		});
		return;
	}
}

//重置
function reset() {
	$("#queryForm")[0].reset();
	//$("#statusFlag").select2('val', "");
	$("#queryForm").find("input[name=roleIds]").val("");
	$("#queryForm").find("input[name=roleNames]").val("");
	//设置zTree不选中任何节点
	var nodes = treeObj.getSelectedNodes();
	if (nodes.length > 0) {
		treeObj.cancelSelectedNode(nodes[0]);
	}
	$("#selectOrgInfo").html("");
}
</script>


<div class="row">
	<div class="col-sm-11">
		<div class="row">
			<div class="col-xs-12">
				<div class="widget-box">
					<div class="widget-header widget-header-small">
						<h5 class="smaller">员工信息查询<span id="selectOrgInfo" style="color:green"></span></h5>
					</div>

					<div class="widget-body">
						<div class="widget-main">
							<form class="form-horizontal" id="queryForm">
								<div class="form-group">
									<div class="col-md-6">
										<label for="empNo" class="control-label input-sm col-md-3">员工编号</label>
										<div class="col-md-7">
												<input type="text" class="form-control input-sm"
												id="empNo" name="empNo">
										</div>
									</div>
									<div class="col-md-6">
										<label for="empName" class="col-md-3 control-label input-sm">员工姓名</label>
										<div class="col-md-7">
											<input type="text" class="form-control input-sm" id="empName"
												name="empName">
										</div>
									</div>
								</div>
								<div class="form-group">
									<div class="col-md-6">
										<label for="statusFlag" class="col-md-3 control-label input-sm">有效标志</label>
										<div class="col-md-7">
											 <select id="statusFlag" name="statusFlag" class="form-control input-sm select2">
												<option value="" selected="selected">请选择</option>
												<option value="90050001">注销</option>
												<option value="90050002">正常</option>
												<option value="90050003">锁定</option>
											</select>
										</div>
									</div>
								</div>
							</form>
							
							<div class="space-6"></div>
		
							<button class="btn btn-xs btn-info" id="btn_query" onclick="query()">
								<i class="icon-search"></i>
								查询
							</button>
							<button class="btn btn-xs btn-default" id="btn_reset" onclick="reset()">
								<i class="icon-undo"></i>
								重置
							</button>
							<button class="btn btn-xs btn-success" id="btn_add" onclick="add()">
								<i class="icon-plus-sign"></i>
								增加
							</button>
							
							
							<div class="space-6"></div>
							
							<div class="table-responsive">
								<table id="empTable" class="table table-condensed table-striped table-bordered table-hover">
									<thead>
										<tr>
											<th width="10%" style="text-align: center"></th>
											<th width="20%">员工编号</th>
											<th width="20%">员工姓名</th>
											<th width="40%">角色名称</th>
										</tr>
									</thead>
									<tbody>
									</tbody>
								</table>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

<!-- Modal 角色选择 -->
<div class="modal fade" id="roleSelector" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel" aria-hidden="true" selectType="selectAll">
</div>
<!-- /.modal -->

<script type="text/javascript">
$(function(){
	$('#roleSelector').on('hidden.bs.modal', function (e) {
		var roles = getRoles();
		$("#roleIds").val(roles.roleIds);
		$("#roleNames").val(roles.roleNames);
	});
});
</script>


</body>
</html>